/* author: Mariana Horita
   mariana.horita@gmail.com
   file: A3E1.cs*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Resolucao
{
    public partial class A3E1 : Form
    {
        public A3E1()
        {
            InitializeComponent();
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            cklItems.Items.Add(txtTexto.Text);
            txtTexto.Clear();
            txtTexto.Focus();
        }

        private void btRemove_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < cklItems.Items.Count; )
            {
                if (cklItems.GetItemCheckState(i) == CheckState.Checked)
                {
                    cklItems.Items.Remove(i);
                }
                else
                {
                    i++;
                }
            }
        }

        private void rdNao_CheckedChanged(object sender, EventArgs e)
        {
            btRemove.Enabled = false;
        }

        private void rdSim_CheckedChanged(object sender, EventArgs e)
        {
            btRemove.Enabled = true;
        }

        private void nudNumeros_ValueChanged(object sender, EventArgs e)
        {
            if (cklItems.CheckedItems.Count > nudNumeros.Value)
            {
                btRemove.Enabled = false;
            }
            else
            {
                btRemove.Enabled = true;
            }
        }

        private void cklItems_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (cklItems.CheckedItems.Count + (e.NewValue == CheckState.Checked? 1 : -1) > nudNumeros.Value)
            {
                btRemove.Enabled = false;
            }
            else
            {
                btRemove.Enabled = true;
            }
        }
    }
}
